package com.iwhalecloud.bss.kite.cucc.web.controller.order;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.inst.IProdInstService;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.UserQueryDTO;
import com.iwhalecloud.bss.kite.cucc.web.controller.reception.LocalCustReceptionController;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.ztesoft.bss.common.util.SpringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/user")
@Api(tags = { "/user - 用户信息" })
public class ProdInstController {

    @Autowired
    public IProdInstService prodInstService;

    @ApiOperation(value ="用户列表查询" )
    @PostMapping("/qryProdInstList")
    public DataResult<UserQueryDTO> pageProdInst(@RequestBody Map map){
        Map<String, Object> querys = (Map<String, Object>) map.get("querys");
        querys.put("pageNum", KiteMapUtils.getString(map, "pageNum"));
        querys.put("pageSize", KiteMapUtils.getString(map, "pageSize"));
        UserQueryDTO userQueryDTO = prodInstService.listProdInst(querys);
        //初始化上下文,直接搜业务号码进变更之前必须要更新上下文数据
        SpringUtil.getBean(LocalCustReceptionController.class).initContext(KiteMapUtils.getString(querys, "custId"), null);

        prodInstService.dealProdInstCustAttr(KiteMapUtils.getString(querys, "custId"), userQueryDTO);
        return ErrorConsts.SUCCESS.getResult(userQueryDTO);
    }

    @ApiOperation(value = "云账号用户列表查询")
    @PostMapping("/qryCloudProdInstList")
    public DataResult<UserQueryDTO> pageCloudProdInst(@RequestBody Map map) {
        Map<String, String> querys = (Map<String, String>) map.get("querys");
        querys.put("pageNum", KiteMapUtils.getString(map, "pageNum"));
        querys.put("pageSize", KiteMapUtils.getString(map, "pageSize"));
        return ErrorConsts.SUCCESS.getResult(prodInstService.listCloudProdInst(querys));
    }


}
